package com.gimi.cloud.jimi.dao.dao.User;

import com.gimi.cloud.jimi.dao.dao.sys.BaseDao;
import com.gimi.cloud.jimi.dao.myMapper.MyMapper;
import com.gimi.cloud.jimi.dto.user.UserDTO;
import com.gimi.cloud.jimi.dto.userInfo.RdUserInfoDTO;
import com.gimi.cloud.jimi.entity.user.User;
import org.apache.ibatis.annotations.*;

/**
 * Create by xiankejin on 2017/10/13
 */
@Mapper
public interface UserDao extends MyMapper<User>,BaseDao<User,UserDTO> {

    @Select("SELECT user_id as userId,user_name AS userName,pwd as pwd,status as status,mobile_phone as mobilePhone,add_time as addTime FROM rd_user WHERE user_name = #{phone} OR mobile_phone = #{phone} LIMIT 1;")
    User checkPhoneAvailable(@Param(value = "phone") String phone);

    //这里表userId改成int类型
    @Select("SELECT * FROM rd_user WHERE user_id = #{userId} LIMIT 1")
    User getUserByUserId(@Param(value = "userId") Integer userId);
    
    @Select("UPDATE rd_user SET pwd = #{pwd} WHERE user_id = #{userId}")
    User modifyPwd(@Param("pwd") String pwd, @Param("userId") String userId);

    /**
     * 插入一条，且返回ID
     * @param isUser
     * @return
     */
    @Options( useGeneratedKeys = true,keyProperty = "userId",keyColumn = "user_id")
    @Insert("INSERT INTO rd_user ( `user_id`,`mobile_phone`,`add_time`,`user_name`) VALUES " +
            "(#{userId},#{mobilePhone},#{addTime},#{userName})")
    int insertReturnUserId(User isUser);

    @Update("UPDATE rd_user SET status = #{status} WHERE user_id = #{userId}")
    void userIsCanBeUsed(RdUserInfoDTO userInfoDTO);
}
